package com.yeung.exam;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

public class 携程_字符解码反转 {


    /*请完成下面这个函数，实现题目要求的功能
    当然，你也可以不按照下面这个模板来作答，完全按照自己的想法来 ^-^
    ******************************开始写代码******************************/
    static String resolve(String expr) {
        Stack<Character> stack = new Stack<>();
        char[] chars = expr.toCharArray();
        String result = "";
        if (expr == null || expr.equals("")) return result;
        for (char aChar : chars) {
            if (aChar == ')') {
                List<Character> tmp = new ArrayList<>();
                //反转部分表达式
                //chu zhan

                while (!stack.empty()) {
                    Character c = stack.pop();
                    if (c == '(') break;
                    else tmp.add(c);
                }
                if (stack.empty()) {
                    StringBuilder sb = new StringBuilder();
                    for (Character cch : tmp) {
                        sb.append(cch);
                    }
                    result += sb.toString();
                } else
                    for (Character character : tmp) {
                        stack.push(character);
                    }
            } else {
                stack.push(aChar);
            }
        }
        while (!stack.empty()) {
            result += stack.pop();
        }
        if (result.contains("(") || result.contains(")")) return "";
//        System.out.println(result);

        return result;
    }

    /******************************结束写代码******************************/


    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String res;

        String _expr;
        try {
            _expr = in.nextLine();
        } catch (Exception e) {
            _expr = null;
        }

        res = resolve(_expr);
        System.out.println(res);
    }
}
